package calbs.socket.analysis;

import calbs.socket.pojo.req.ReqData;
import calbs.socket.pojo.req.ReqUploadAbLineMsg;
import calbs.socket.tool.CHexConver;
import calbs.socket.tool.LatLngTool;
import com.alibaba.fastjson.JSON;

/**
 * 上传AB线接口
 * Created by Q on 2017/8/3.
 */
public class UploadAblineAnalysisImp implements AnalysisI<ReqUploadAbLineMsg>{
    @Override
    public ReqData<ReqUploadAbLineMsg> analysisMsg(ReqData<ReqUploadAbLineMsg> reqData){
        ReqUploadAbLineMsg reqUploadAbLineMsg = reqData.getBody();
        String content = reqUploadAbLineMsg.getContent();
        Integer device = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setDevice(device.toString());
        content = content.substring(2*4);
        Long aPointLongitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointLongitude(LatLngTool.getLatLngByOld(aPointLongitude));
        content = content.substring(2*4);
        Long aPointLatitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointLatitude(LatLngTool.getLatLngByOld(aPointLatitude));
        content = content.substring(2*4);
        Integer aPointHeight = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointHeight(LatLngTool.getHeightByOld(aPointHeight));
        content = content.substring(2*4);
        Long bPointLongitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointLongitude(LatLngTool.getLatLngByOld(bPointLongitude));
        content = content.substring(2*4);
        Long bPointLatitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointLatitude(LatLngTool.getLatLngByOld(bPointLatitude));
        content = content.substring(2*4);
        Integer bPointHeight = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointHeight(LatLngTool.getHeightByOld(bPointHeight));
        content = content.substring(2*4);

        Long basex = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasex(basex+"");
        content = content.substring(2*4);

        Long basey = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasey(basey+"");
        content = content.substring(2*4);

        Long basez = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasez(basez+"");
        content = content.substring(2*4);


        Integer fieldNameLength = Integer.parseInt(content.substring(0,2*2),16);
        String fieldName = CHexConver.hexStr2Str(content.substring(2*2,fieldNameLength*2+4));
        reqUploadAbLineMsg.setFieldName(fieldName);
        content = content.substring(2*2+fieldNameLength*2);
        Integer abLineNameLength = Integer.parseInt(content.substring(0,2*2),16);
        String abLineName = CHexConver.hexStr2Str(content.substring(2*2,abLineNameLength*2+4));
        reqUploadAbLineMsg.setAbLineName(abLineName);
        content = content.substring(2*2+abLineNameLength*2);
        Integer utcTime = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setUtcTime(utcTime.toString());
        return reqData;
    }


    public static void main(String[] args) {
        ReqUploadAbLineMsg reqUploadAbLineMsg = new ReqUploadAbLineMsg();
        String content="7E7D240816003DDF0C074CCB06EF67DB026488DB00065B3006EF67B8026484C300065541F30108C81A01751E186A27E70006506C6F75676800074C696E654142";
        //String content = "7E7D24000F003DFA0000C3500736AC0901DA422A0001E4720736AC0D01DA42020001E5C0EF34D2FC1BE7F7F2138AF4010006506C6F75676800074C696E654142305A0937C77E7D";
        content = content.substring(2*2);
        content= content.substring(2*1);
        content= content.substring(2*2);
        content= content.substring(2*2);
        content= content.substring(2*1);
        content= content.substring(0,content.length()-2*2) ;
        Integer device = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setDevice(device.toString());
        content = content.substring(2*4);
        Long aPointLongitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointLongitude(LatLngTool.getLatLngByOld(aPointLongitude));
        content = content.substring(2*4);
        Long aPointLatitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointLatitude(LatLngTool.getLatLngByOld(aPointLatitude));
        content = content.substring(2*4);
        Integer aPointHeight = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setaPointHeight(LatLngTool.getHeightByOld(aPointHeight));
        content = content.substring(2*4);
        Long bPointLongitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointLongitude(LatLngTool.getLatLngByOld(bPointLongitude));
        content = content.substring(2*4);
        Long bPointLatitude = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointLatitude(LatLngTool.getLatLngByOld(bPointLatitude));
        content = content.substring(2*4);
        Integer bPointHeight = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setbPointHeight(LatLngTool.getHeightByOld(bPointHeight));
        content = content.substring(2*4);

        System.out.println("x:"+content.substring(0,2*4));
        Long basex = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasex(basex+"");
        content = content.substring(2*4);

        System.out.println("y:"+content.substring(0,2*4));
        Long basey = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasey(basey+"");
        content = content.substring(2*4);

        System.out.println("z:"+content.substring(0,2*4));
        Long basez = Long.parseLong(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setBasez(basez+"");
        content = content.substring(2*4);

        Integer fieldNameLength = Integer.parseInt(content.substring(0,2*2),16);
        String fieldName = CHexConver.hexStr2Str(content.substring(2*2,fieldNameLength*2+4));
        reqUploadAbLineMsg.setFieldName(fieldName);
        content = content.substring(2*2+fieldNameLength*2);
        Integer abLineNameLength = Integer.parseInt(content.substring(0,2*2),16);
        String abLineName = CHexConver.hexStr2Str(content.substring(2*2,abLineNameLength*2+4));
        reqUploadAbLineMsg.setAbLineName(abLineName);
        content = content.substring(2*2+abLineNameLength*2);
        Integer utcTime = Integer.parseInt(content.substring(0,2*4),16);
        reqUploadAbLineMsg.setUtcTime(utcTime.toString());
        System.out.println(JSON.toJSONString(reqUploadAbLineMsg));
    }
}
